package com.zhucx.utils;

import java.io.*;
import java.util.*;
import java.util.Map.Entry;

public class ResourceUtil {
    private static ResourceBundle bundle;

    public ResourceUtil() {
    }

    public static ResourceBundle getResourceBundle() {
        if (bundle == null) {
            bundle = ResourceBundle.getBundle("config");
        }

        return bundle;
    }

    public static String getString(String key) {
        String result = null;

        try {
            result = new String(getResourceBundle().getString(key).getBytes("ISO-8859-1"), "utf-8");
        } catch (MissingResourceException var3) {
            System.out.println("ConfigBundle:getString error!" + var3.toString());
        } catch (UnsupportedEncodingException var4) {
            var4.printStackTrace();
        }

        return result;
    }

    public static boolean setProperties(String fileName, String propertyName, String propertyValue) {
        boolean result = true;
        File file = new File(fileName);
        if (file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException var9) {
                var9.printStackTrace();
            }
        }

        Properties prop = new Properties();

        try {
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
            prop.load(new InputStreamReader(in, "utf-8"));
            in.close();
            prop.setProperty(propertyName, propertyValue);
            FileOutputStream out = new FileOutputStream(file);
            prop.store(out, "");
            out.flush();
            out.close();
        } catch (Exception var8) {
            var8.printStackTrace();
        }

        return result;
    }

    public static boolean setProperties(String fileName, Map<String, String> map) {
        boolean result = true;
        Properties prop = new Properties();
        File file = new File(fileName);
        if (file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException var8) {
                var8.printStackTrace();
            }
        }

        try {
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
            prop.load(new InputStreamReader(in, "utf-8"));
            in.close();
            Iterator var6 = map.entrySet().iterator();

            while(var6.hasNext()) {
                Entry<String, String> entry = (Entry)var6.next();
                prop.setProperty((String)entry.getKey(), (String)entry.getValue());
            }

            FileOutputStream out = new FileOutputStream(file);
            prop.store(out, "");
            out.flush();
            out.close();
        } catch (Exception var9) {
            var9.printStackTrace();
        }

        return result;
    }

    public static void main(String[] args) {
        setProperties("config.properties", "AREA_NAME", "信阳市");
        System.out.println(getString("AREA_NAME"));
    }
}

